<?php
/**
 * Formulaire de modification du person
 *
 * @author Samir
 */
class Form_Modification_Person extends ZendX_JQuery_Form {
	
	private $table_Persons;
	//public $userId = 1;
	public function __construct($options = null){
		parent::__construct($options);
		//$this->table_Persons = new Model_Database_PersonDb();
	}
	
	public function init(){

		require_once APPLICATION_PATH . '../decorators/formElementDecorator.php';
		
		$decorators = new Decorator_FormElement();
		
		$this->setName('form_modification_person');

        $civilite = new Zend_Form_Element_Select('civility');
		$civilite->setLabel('Civilité')
           		 ->addMultiOptions(array("" => "Choisir...", "Mr" => "Monsieur",  "Mme" => "Madame", "Mlle" => "Mademoiselle" ))
            	->setRequired(true)
            	->setErrorMessages(array('Please enter your name.'))
            	//->setAttrib('class', 'validate[required]')
            	->addDecorator($decorators);
        $this->addElement($civilite);
		
        $nom = new Zend_Form_Element_Text('firstname');
		$nom->setRequired(true)
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'validate[required],text-input')
	         ->setLabel(('Nom'))
	         ->addDecorator($decorators);
	         
		$this->addElement($nom);	
		
		
		/*$prenom = new Zend_Form_Element_Text('lastname');
		$prenom->setRequired(true)
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'validate[required] text-input')
	         ->setLabel(('Prénom'))
	         ->addDecorator($decorators);
		$this->addElement($prenom);	

        /*$function = new Zend_Form_Element_Select('function');
		$function-> addDecorator($decorators);
		$function->setLabel('Fonction')
				 ->setAttrib('class', 'validate[required]')
				 ->addMultiOptions(array("" =>  "Choisir ...", 'president' => 'Président', 
										'vice-president' =>'Vice-Président', 'tresorier' => 'Trésorie', 
										'vice-tresorier' => 'Vice-Trésorie','secretaire' => 'Secrétaire'
			 							,'vice-secretaire' => 'Vice-Secrétaire', 'administrator'=>'Administrator','charger-de-mission' =>'Chargé de Mission', 'animateur_bdi'=>'Animateur BDI', 'permanent'=>'Permanent','formateur-relais' =>'Formateur Relais'));
        $this->addElement($function); 
          
        $echelon = new Zend_Form_Element_Select('echelon');
		$echelon-> addDecorator($decorators);
		$echelon->setLabel('Echelon')
				->setAttrib('class', 'validate[required]')
				 ->addMultiOptions(array("" =>  "Choisir ...", 'apel-etablissement' => 'Apel d\'établissement', 
										'apel-departementale' =>'Apel départementale', 'apel-academique' => 'Apel Académique', 
										'apel-nationnale' => 'Apel Nationnale'));
        $this->addElement($echelon); 

        $email = new Zend_Form_Element_Text('email');
		$email->setRequired(true)
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'validate[required,custom[email]] text-input')
	         ->setLabel(('Email'))
			 ->addDecorator($decorators);;	
		$this->addElement($email);	

		$address = new Zend_Form_Element_Textarea('address');
		$address->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'validate[required] text-input')
		         ->setLabel(('Adresse'))
		         ->setAttrib('rows',3) 
		         ->setAttrib('cols',23)
			 	 ->addDecorator($decorators);
	 	$this->addElement($address);
	 		
		$zipcode = new Zend_Form_Element_Text('zipcode');
		$zipcode->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'validate[required,custom[onlyNumber],length[5]] text-input')
		         ->setLabel(('Code Postal'))
				 ->addDecorator($decorators);
		$this->addElement($zipcode);
					
		$city = new Zend_Form_Element_Text('city');
		$city->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'validate[required]')
		         ->setLabel(('Ville'))
				 ->addDecorator($decorators);
		$this->addElement($city);
		 
		$phone = new Zend_Form_Element_Text('telephone');
		$phone->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'validate[required,custom[telephone]] text-input')
		         ->setLabel(('Télephone'))
				 ->addDecorator($decorators);
				 $this->addElement($phone);	
		
        
		$site = new Zend_Form_Element_Text('url');
		$site->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', "validate['url']")
		         ->setLabel(('Site web'))
				 ->addDecorator($decorators);
		$this->addElement($site);			

        $password = new Zend_Form_Element_Password('password');
        $password->setLabel('Mot de passe')
        		// ->setRequired(true)
        		 ->addFilter('StripTags')
        		 ->addFilter('StringTrim')
        		 ->setAttrib('class', 'validate[required,length[6,15]] text-input')
        		 ->addDecorator($decorators);
        $this->addElement($password);      

        $password_bis = new Zend_Form_Element_Password('password_confirmation');
        $password_bis->setLabel('Retapez le mot de passe')
		        //->setRequired(true)
		        ->addFilter('StripTags')
		        ->addFilter('StringTrim')
		        ->setAttrib('class', 'validate[required,confirm[password]] text-input')
		        ->addDecorator($decorators);
        $this->addElement($password_bis);
		

		$extensions = array('jpg');
		$photo = new Zend_Form_Element_File('photo');
		$photo->setLabel('Photo')
			         ->setDestination('../temp/uploads/')
			         ->setAttrib('class', 'filefields')
			         ->setAttrib('accept', join('|', $extensions))
			         ->addValidator('Extension', false, join(',', $extensions))
			         ->addDecorator($decorators);			
        $this->addElement($photo);
		$aucun = new Zend_Form_Element_Checkbox('aucun');
		$aucun->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("Aucun"))
	        		 ->addDecorator($decorators);
	    $this->addElement($aucun);
                
		$icf = new Zend_Form_Element_Checkbox('icf');
		$icf->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("UCF"))
	        		 ->addDecorator($decorators);
	    $this->addElement($icf);
	    
		$ecole = new Zend_Form_Element_Checkbox('ecole');
		$ecole->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("Ecole et monde professionnel"))
	        		 ->addDecorator($decorators);
	    $this->addElement($ecole);
	    
		$pastorale = new Zend_Form_Element_Checkbox('rap');
		$pastorale->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("RAP"))
	        		 ->addDecorator($decorators);
	    $this->addElement($pastorale);
	    
		$securite = new Zend_Form_Element_Checkbox('securite');
		$securite->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("Securite aux abords des etablissements"))
	        		 ->addDecorator($decorators);
	    $this->addElement($securite);
        
	    $this->addElement('hidden', 'new_parent_id', array('value' =>'0',
            'decorators' => array('ViewHelper',
                array(array('div' => 'HtmlTag'), array('tag' => 'div', 'class' => "hidden")))
        ));
	    
        $this->addElement(
                'submit',
                'submit',
                array(
                    'decorators' => array(
                        'ViewHelper',
                        'Errors',
                        array('Description', array('tag' => 'p', 'class' => 'description')),
                        array('HtmlTag', array('tag' => 'span', 'class' => "aligne-centre ")),
                        array(array('div' => 'HtmlTag'),
                            array('tag' => 'p', 'class' => "form-table"))
                    ),
                    'label' => 'Valider',
                    'class'=>'submit'
        ))->clearDecorators();
	    
	}
    public function save($data){
       
        $id = $this->table_Persons->savePerson($data);
        return $id;
    }
    
    //Remplis les données du form
    public function getDataForm($id,$format_date = true)
    {
           $data =array();
           $tab_Person =  $this->table_Persons->fetchAll("id = '$id'");
           $data = $tab_Person->toArray();
           $data = $data[0];
           
           return $data;
    }*/
    }	
}
